from django.contrib.auth.models import User
from django.db import models

# Create your models here.
from django.db import models

class JobPosition(models.Model):

    title = models.CharField(max_length=100, verbose_name='职位名称')
    company = models.CharField(max_length=100, verbose_name='公司名称')
    location = models.CharField(max_length=100, verbose_name='工作地点')
    salary_range = models.CharField(max_length=50, verbose_name='薪资范围')
    description = models.TextField(verbose_name='职位描述')
    requirements = models.TextField(verbose_name='职位要求')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '职位信息'
        verbose_name_plural = '职位信息'
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.company} - {self.title}"


class ApplyRecord(models.Model):
    STATUS_CHOICES = [
        ('pending', '待处理'),
        ('reviewing', '审核中'),
        ('accepted', '已接受'),
        ('rejected', '已拒绝'),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='job_applications')
    job = models.ForeignKey(JobPosition, on_delete=models.CASCADE, related_name='applications')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending', verbose_name='申请状态')
    applied_at = models.DateTimeField(auto_now_add=True, verbose_name='申请时间')

    class Meta:
        verbose_name = '职位申请'
        verbose_name_plural = '职位申请'
        ordering = ['-applied_at']